﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Husb.Framework;
using Husb.Framework.DataAccess;


namespace Crawler.Model
{
    [Serializable]
    public class CaptureRuleInfo : EntityBase
    {
        #region Private Variables
        private System.Guid id;
        private System.Guid taskItemId;
        private System.String name;
        private System.String startString;
        private System.String endString;
        private System.Int32? contentType;
        private System.Int32 category;
        private System.Int32? matchMethod;
        private System.String matchRegex;
        private System.Int32? processMethod;
        private System.String prefix;
        private System.String suffix;
        private System.String replaceRegex;
        private System.Int32 orderNumber;
        private System.String nextPage;
        //private System.Int32 maxPageCount;
        private System.String nextPageUrl;
        [NotUndoable]
        private TaskItemInfo taskItem;
        private System.String url;
        #endregion


        #region Properties
        /// <summary>
        /// 
        /// </summary>		
        public System.Int32 OrderNumber
        {
            get { return orderNumber; }
            set { orderNumber = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Guid TaskItemId
        {
            get { return taskItemId; }
            set { taskItemId = value; }
        }
        public TaskItemInfo TaskItem
        {
            get
            {
                if (taskItem == null)
                {
                    throw new NullReferenceException("此 捕获规则 所属的 任务项 对象为空，不符合逻辑。");
                }
                return taskItem;
            }
            set
            {
                taskItem = value;
            }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String Url
        {
            get { return url; }
            set { url = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Guid Id
        {
            get { return id; }
            set { id = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String Name
        {
            get { return name; }
            set { name = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String StartString
        {
            get { return startString; }
            set { startString = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String EndString
        {
            get { return endString; }
            set { endString = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Int32? ContentType
        {
            get { return contentType; }
            set { contentType = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Int32 Category
        {
            get { return category; }
            set { category = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Int32? MatchMethod
        {
            get { return matchMethod; }
            set { matchMethod = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String MatchRegex
        {
            get { return matchRegex; }
            set { matchRegex = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Int32? ProcessMethod
        {
            get { return processMethod; }
            set { processMethod = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String Prefix
        {
            get { return prefix; }
            set { prefix = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String Suffix
        {
            get { return suffix; }
            set { suffix = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String ReplaceRegex
        {
            get { return replaceRegex; }
            set { replaceRegex = value; }
        }

        /// <summary>
        /// 
        /// </summary>		
        public System.String NextPage
        {
            get { return nextPage; }
            set { nextPage = value; }
        }

        /// <summary>
        /// 
        /// </summary>		
        public System.String NextPageUrl
        {
            get { return nextPageUrl; }
            set { nextPageUrl = value; }
        }
        #endregion

        #region GenerateFilterExpression
        /// <summary>
        /// 产生组合查询的条件
        /// </summary>
        /// <param name="captureRule">当前实体类<see cref="CaptureRuleInfo"/>CaptureRuleInfo</param>
        /// <returns></returns>
        public override string FilterExpression
        {
            get
            {
                string where = "";
                where += DataAccessHelper.GetPartWhereCondition("Id", Id);
                where += DataAccessHelper.GetPartWhereCondition("Name", Name);
                where += DataAccessHelper.GetPartWhereCondition("StartString", StartString);
                where += DataAccessHelper.GetPartWhereCondition("EndString", EndString);
                where += DataAccessHelper.GetPartWhereCondition("ContentType", ContentType);
                where += DataAccessHelper.GetPartWhereCondition("Category", Category);
                where += DataAccessHelper.GetPartWhereCondition("MatchMethod", MatchMethod);
                where += DataAccessHelper.GetPartWhereCondition("MatchRegex", MatchRegex);
                where += DataAccessHelper.GetPartWhereCondition("ProcessMethod", ProcessMethod);
                where += DataAccessHelper.GetPartWhereCondition("Prefix", Prefix);
                where += DataAccessHelper.GetPartWhereCondition("Suffix", Suffix);
                where += DataAccessHelper.GetPartWhereCondition("ReplaceRegex", ReplaceRegex);

                return where;
            }
        }
        #endregion

        #region Validate
        /// <summary>
        /// 数据验证
        /// </summary> 
        protected override void Validate()
        {
            //AddRule("Price", "Price must be greater than or equal to 0", this.Price < 0);
            AddRule("Name", "捕获规则名称不能为空", string.IsNullOrEmpty(this.Name));
        }
        #endregion

        
    }
}
